package com.test.article;

import java.sql.*;

public class testUser {
    public static void main(String[] args) {
        // 加载驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            // 创建连接
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://152.136.172.246:3306/lore_user", "root", "xiaoyou");

            // 发送sql语句
            PreparedStatement statement = connection.prepareStatement(
                    "select uid, gender, school_id, user_name from user");

            // 执行查询、得到一个结果集合
            ResultSet resultSet = statement.executeQuery();

            // 遍历结果集
            while (resultSet.next()) {
                // 取出当前行的所有数据
                System.out.println("uid:" + resultSet.getLong("uid"));
                System.out.println("gender:" + resultSet.getLong("gender"));
                System.out.println("school_id:" + resultSet.getString("school_id"));
                System.out.println("user_name:" + resultSet.getString("user_name"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
